import { Message } from 'element-ui';
import validate from '@/utils/validate';

const { isEmpty, isMobile } = validate;

export default function check (checkObj) {
  let checkRes = true;
  const validKeys = [
    { key: 'name', name: '仓库名称' },
    { key: 'type', name: '仓库类型' },
    { key: 'status', name: '仓库状态' },
    { key: 'keeper', name: '仓管员' },
    { key: 'department', name: '部门' },
    { key: 'mobile', name: '联系电话' }
  ];

  for (const valid of validKeys) {
    const checkMid = isEmpty(checkObj[valid.key]);
    if (checkMid) {
      Message.error(`${valid.name}不能为空`);
      checkRes = false;
      break;
    }
  }

  if (!isMobile(checkObj.mobile)) {
    Message.error('手机号码输入不正确');
    checkRes = false;
  }

  if (checkObj.allowingSite && isEmpty(checkObj.storageSites)) {
    Message.error('仓位数量不能为空');
    checkRes = false;
  }

  return checkRes;
}
